#include "stdafx.h"
#include "CppUnitTest.h"

#include "System/Platform/FilePath.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Native::System;

namespace TestNativePlatform
{
    TEST_CLASS(FilePath_Tester)
    {
    public:
        wstring _relative_head;
        wstring _absolute_head;
        wstring _directory_body;
        wstring _filename;
        wstring _relative_directory;
        wstring _absolute_directory;
        wstring _relative_fullpath;
        wstring _absolute_fullpath;

        FilePath_Tester()
        {
            _relative_head = L"..\\";
            _absolute_head = L"D:\\";
            _directory_body = L"Native\\Source\\";
            _filename = L"Test.h";

            _relative_directory = _relative_head + _directory_body;
            _absolute_directory = _absolute_head + _directory_body;
            _relative_fullpath = _relative_directory + _filename;
            _absolute_fullpath = _absolute_directory + _filename;
            
        }

        TEST_METHOD(FilePath_ConstructByPath)
        {
            CFilePath filepath_relative_directory(_relative_directory);

            Assert::IsTrue(filepath_relative_directory.Relative());
            Assert::AreEqual(filepath_relative_directory.Path().ToString(), _relative_directory);
            Assert::AreEqual(filepath_relative_directory.Directory().ToString(), _relative_directory);
            Assert::IsTrue(filepath_relative_directory.Filename().Empty());

            CFilePath filepath_absolute_directory(_absolute_directory);

            Assert::IsFalse(filepath_absolute_directory.Relative());
            Assert::AreEqual(filepath_absolute_directory.Path().ToString(), _absolute_directory);
            Assert::AreEqual(filepath_absolute_directory.Directory().ToString(), _absolute_directory);
            Assert::IsTrue(filepath_absolute_directory.Filename().Empty());
            
            CFilePath filepath_relative_fullpath(_relative_fullpath);

            Assert::IsTrue(filepath_relative_fullpath.Relative());
            Assert::AreEqual(filepath_relative_fullpath.Path().ToString(), _relative_fullpath);
            Assert::AreEqual(filepath_relative_fullpath.Directory().ToString(), _relative_directory);
            Assert::AreEqual(filepath_relative_fullpath.Filename().ToString(), _filename);

            CFilePath filepath_absolute_fullpath(_absolute_fullpath);

            Assert::IsFalse(filepath_absolute_fullpath.Relative());
            Assert::AreEqual(filepath_absolute_fullpath.Path().ToString(), _absolute_fullpath);
            Assert::AreEqual(filepath_absolute_fullpath.Directory().ToString(), _absolute_directory);
            Assert::AreEqual(filepath_absolute_fullpath.Filename().ToString(), _filename);

            CFilePath filepath_filename(_filename);

            Assert::IsTrue(filepath_filename.Relative());
            Assert::AreEqual(filepath_filename.Path().ToString(), wstring(L".\\") + _filename);
            Assert::AreEqual(filepath_filename.Directory().ToString(), wstring(L".\\"));
            Assert::AreEqual(filepath_filename.Filename().ToString(), _filename);
        }

        TEST_METHOD(FilePath_ConstructByDirectoryAndFilename)
        {
            CFilePath filepath_relative_directory(_relative_directory, L"");

            Assert::IsTrue(filepath_relative_directory.Relative());
            Assert::AreEqual(filepath_relative_directory.Path().ToString(), _relative_directory);
            Assert::AreEqual(filepath_relative_directory.Directory().ToString(), _relative_directory);
            Assert::IsTrue(filepath_relative_directory.Filename().Empty());

            CFilePath filepath_absolute_directory(_absolute_directory, L"");

            Assert::IsFalse(filepath_absolute_directory.Relative());
            Assert::AreEqual(filepath_absolute_directory.Path().ToString(), _absolute_directory);
            Assert::AreEqual(filepath_absolute_directory.Directory().ToString(), _absolute_directory);
            Assert::IsTrue(filepath_absolute_directory.Filename().Empty());

            CFilePath filepath_relative_fullpath(_relative_directory, _filename);

            Assert::IsTrue(filepath_relative_fullpath.Relative());
            Assert::AreEqual(filepath_relative_fullpath.Path().ToString(), _relative_fullpath);
            Assert::AreEqual(filepath_relative_fullpath.Directory().ToString(), _relative_directory);
            Assert::AreEqual(filepath_relative_fullpath.Filename().ToString(), _filename);

            CFilePath filepath_absolute_fullpath(_absolute_directory, _filename);

            Assert::IsFalse(filepath_absolute_fullpath.Relative());
            Assert::AreEqual(filepath_absolute_fullpath.Path().ToString(), _absolute_fullpath);
            Assert::AreEqual(filepath_absolute_fullpath.Directory().ToString(), _absolute_directory);
            Assert::AreEqual(filepath_absolute_fullpath.Filename().ToString(), _filename);

            CFilePath filepath_filename(L"", _filename);

            Assert::IsTrue(filepath_filename.Relative());
            Assert::AreEqual(filepath_filename.Path().ToString(), wstring(L".\\") + _filename);
            Assert::AreEqual(filepath_filename.Directory().ToString(), wstring(L".\\"));
            Assert::AreEqual(filepath_filename.Filename().ToString(), _filename);
        }
    };
}